#include <bits/stdc++.h>
using namespace std;
int t,n,m,l,v,v0,s,a,u,chaosu=0,panduan=0;
double c,b,shijian;
int w[100010],jilu[100010];
double h[100010],zhongdian[100010];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>n>>m>>l>>v;
        for(int j=1;j<=n+1;j++)
        {
            if(j==n+1) {
                for(int k=1;k<=m;k++){
                    cin>>w[k];
                    for(int r=1;r<=j;r++)if (h[r]<=w[k] && zhongdian[r]>=w[k]) {
                        chaosu++;
                        break;
                    }
                }
            }
            else{

                    cin>>s>>v0>>a;
            if(v0<=v){
                h[j]=0;
                zhongdian[j]=0;
            }
            else {
                h[j]=s;
                zhongdian[j]=l;
            }
            }

        }
         cout<<chaosu;
         cout<<0;
        }
    return 0;
}
